
<template>
  <!-- 上传对话框 -->
  <el-dialog
    title="上传"
    :visible.sync="dialogVisible"
    width="35%"
    style="text-align: center"
  >
  <el-input v-model="id" v-show="false"></el-input>
      <el-input v-model="newcover" placeholder="请填入图片链接"></el-input>
      <el-button
        type="danger"
        icon="el-icon-close"
        @click="dialogVisible = false"
        >取 消</el-button
      >
      <el-button type="success" icon="el-icon-check" @click="reusercover"
        >确 定</el-button
      >
  </el-dialog>
</template>
<script>
import { success } from "log-symbols";

export default {
  name: "Recover",
  data() {
    return {
      newcover: "",
      // oldusername: "",
      dialogVisible: false,
      id:''
    };
  },
  methods: {
    reusercover() {
      let data = new FormData();
      data.append("newcover", this.newcover);
      data.append("id", this.id);
      this.$axios.post("/reusercover", data).then((successResponse) => {
        if (successResponse.data.code === 200) {
          
          this.$emit('getcover')
            // this.$emit('reloads')
          // this.getusername()
          this.$router.go(0);
         
          this.open2();
          this.dialogVisible = false;
        } else {
          this.open4();
          this.dialogVisible = false;
        }
        
        
      });
    },
    getusercoverbyid() {
      let data = new FormData();
      data.append('id',this.id)
      this.$axios.post("/getusercoverbyid",data).then((resp) => {
        this.newcover = resp.data;
        
        console.log(resp);
      });
    },
    open2() {
      this.$message({
        message: "成功修改头像",
        type: "success",
      });
    },
    open4() {
      this.$message({
        message: "失败修改头像",
        type: "error",
      });
    },
    getid() {
      this.$axios.get("/getid").then((resp) => {
        this.id = resp.data
        console.log(this.id);
      })
      
    }
  },
  mounted: function () {
    // this.getusername();
    this.getid();
  },
  
};
</script>
<style scoped>
.el-dialog {
  position: relative;
}
.queding {
  position: absolute;
  margin-left: 151px;
  margin-top: -19px;
}
</style>